home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-20 | 30.7 KB | 1,143 lines |
- #@package: VisualTclX-menu VxMenu VxMenuGetButton VxOptionMenu \
- VxOptionMenuGetSelected VxOptionMenuReplaceOptions VxOptionMenuSetSelected
- #
- # Menu creation routines
- #
- #
- # VxMenu
- # builds the insides of a menu bar, Uset VxMenuGetButton to get
- # the reference to a menu item widget, ie VxMenuGetButton $dlog "New"
- #
- # Syntax:
- # VxMenu formDialog menuBar menuList defaultCB
- #
- # Arguments:
- # formDialog - widgetName of form dialog
- # menuBar - widgetName of menubar
- # menuList - menu list to build from
- # defaultCB - default callback to call if they aren't set
- # in menuList
- #
- #
- # each item in menulist can contain the following indices
- # OFFSET Description
- # ----- -----------
- # 0 Type, one of following pd, hp, cs, bt, sp,
- # sp, tb, sc
- # 1 Name, name of the button
- # 2 mnemonic
- # 3 accelerator
- # 4 acceleratorString
- # 5 callback to associate with button
- # 6 If a toggle button this sets the initial state
- #
- # Use VxMenuGetButton to get the buttons in the menu.
- #
- proc VxMenu {dlog menubar menuList defaultCB} {
- # different codes for various objects, the only one that is non
- # obvious here is cs, it stands for cascade.
- keylset typeKey pd VtPulldown hp VtPulldown cs VtPulldown \
- bt VtPushButton sp VtSeparator tb VtToggleButton \
- sc EndCascade
-
- set cascadeStack ""
- foreach m $menuList {
-
- set type [lindex $m 0]
- set cmd [keylget typeKey $type]
- set label [lindex $m 1]
-
- # convert the ellipses to '+'
- set name [translit ". " "+_" $label]
-
- switch $type {
- pd - hp {
- # Creating a pulldown menu
- lappend cmd "$menubar.$name"
- }
- sc {
- # closing a cascade, pop the last pulldown off the stac
- set lastPd [lvarpop cascadeStack]
- continue
- }
- sp {
- lappend cmd "$lastPd.$name" -allowDuplicateName
- eval $cmd
- continue
- }
- default {
- lappend cmd "$lastPd.$name"
- }
- }
-
- # This is a help pulldown
- if {$type == "hp"} { lappend cmd -help }
-
- # set the label
- lappend cmd -label $label
-
-
- # now set the various placement dependant options
- if { [lindex $m 2] != ""} {
- lappend cmd -mnemonic [lindex $m 2 ]
- }
-
- if { [lindex $m 3] != ""} {
- lappend cmd -accelerator [lindex $m 3]
- }
-
- if { [lindex $m 4] != ""} {
- lappend cmd -acceleratorString [lindex $m 4]
- }
-
- set cb [lindex $m 5]
- if {$cb != ""} {
- lappend cmd -callback $cb
- } elseif {$type != "pd" && $type != "hp" && $type != "cs"} {
- lappend cmd -callback $defaultCB
- }
-
- # Toggle buttons have a 6th option, the initial set state
- if { $type == "tb" && [lindex $m 6] != "" } {
- lappend cmd -value [lindex $m 6]
- }
-
-
- switch $type {
- pd - hp {
- set lastPd [eval $cmd]
- VxSetVar $dlog MenuButton($label) $lastPd
- }
- cs {
- set cascade [eval $cmd]
- lvarpush cascadeStack $lastPd
- set lastPd $cascade
- VxSetVar $dlog MenuButton($label) $lastPd
- }
- default {
- set but [eval $cmd]
-
- VxSetVar $dlog MenuButton($label) $but
- }
- }
- }
- }
-
- #
- #VxMenuGetButton
- # Gets the widget name of a button in a menu created with VxMenu
- #
- #Syntax:
- # VxMenuGetButton widgetName buttonLabel
- #
- #Arguments:
- # widgetName - Widget name of the menu created by VxMenu
- # buttonLabel - label of the button to retrieve
- #
- proc VxMenuGetButton {dlog name} {
- return [VxGetVar $dlog MenuButton($name)]
- }
-
-
- #------------------------------------------------------------
- #
- # Routines for option menus
- #
- #
- # VxOptionMenu object.name label options defaultCB selection
- #
- # Returns an option menu that contains pushbuttons for the
- # options specified.
- #
- # object.name - widget hierarchy of option menu
- # label - option menu label,
- # (e.g. "filename:")
- # options - tcl list of options
- # (to be used as labels for the pushbuttons)
- # (e.g. {one two three})
- # defaultCB - callback called when option menu changes
- # selection - option which is initially selected
- # (e.g. "one")
- #
- #
- # VxOptionMenuGetSelected menu
- #
- # Returns the label of the selected item in an option menu that
- # was created by VxOptionMenu
- #
- # widgetName - name of menu returned by VxOptionMenu
- #
- # VxOptionMenuSetSelected menu selection
- #
- # Sets the option menu's value to be <selection>. "selection" refers
- # to the label of the selected pushbutton. The option menu
- # referenced must have been created by VxOptionMenu.
- #
- # widgetName - name of menu returned by VxOptionMenu
- # selection - label of option to be selected.
- #
- #
- # VxOptionMenuReplaceOptions widgetName options selection
- #
- # Returns the label of the selected item in an option menu that
- #
- # widgetName - name of menu returned by VxOptionMenu
- # options - tcl list of options
- # (to be used as labels for the pushbuttons)
- # (e.g. {one two three})
- # selection - option which is initially selected
- # (e.g. "one")
- #
- #
-
- proc _SetOptions {menu options selection} {
- #
- # make option menu buttons and assign to userdata
- set i 0
- foreach buttonLabel $options {
- set button [VtPushButton $menu.button$i -label $buttonLabel]
- keylset allButtons button$i $buttonLabel
- incr i
- }
- if {![info exists allButtons]} {
- VtSetValues $menu -userData {}
- return $menu
- } else {
- keylset allButtons ":labelList" $options
- VtSetValues $menu -userData $allButtons
- }
-
-
- if {$selection == "" } {
- #set to the first one
- VtSetValues $menu -selectedWidget $menu.button0
- } else {
- VxOptionMenuSetSelected $menu $selection
- }
- }
-
-
- proc VxOptionMenu {name label options CB selection} {
- set menu [VtOptionMenu $name -label $label]
- if {$CB != ""} {
- VtSetValues $menu -callback $CB
- }
-
- _SetOptions $menu $options $selection
- return $menu
- }
-
- proc VxOptionMenuGetSelected {menu} {
- set selectedWidget [VtGetValues $menu -selectedWidget]
- set allButtons [VtGetValues $menu -userData]
- set button [VxGetShortName $selectedWidget]
- return [keylget allButtons $button]
- }
-
- proc VxOptionMenuSetSelected {menu selected} {
- set allButtons [VtGetValues $menu -userData]
- set labelList [keylget allButtons ":labelList"]
- set button [lsearch $labelList $selected]
- if {$button == -1} {
- error "VxOptionMenuSetSelected: selection invalid: $selected"
- }
-
- VtSetValues $menu -selectedWidget $menu.button$button
- }
-
- proc VxOptionMenuReplaceOptions {menu options selection} {
- #
- # get button list
- set allButtons [VtGetValues $menu -userData]
-
- #
- # destroy old buttons
- if {$allButtons != "{}"} {
- foreach button [keylkeys allButtons] {
- if {$button != ":labelList"} {
- VtDestroy $menu.$button
- }
- }
- }
-
- #
- # make new buttons
- _SetOptions $menu $options $selection
- }
-
- #@packend
-
-
- #@package: VisualTclX-label VxList VxText VxRowColumn VxRadioBox \
- VxCheckBox VxComboBox
-
- #
- # The following five routines add the -label -title functionality to
- # VtList VtText VtRowColumn VtRadioBox VtCheckBox
- #
-
- proc VxList {name args} {
- eval _VxBox VtList $name $args
- }
-
- proc VxText {name args} {
- eval _VxBox VtText $name $args
- }
-
- proc VxRadioBox {name args} {
- eval _VxBox VtRadioBox $name $args
- }
-
- proc VxCheckBox {name args} {
- eval _VxBox VtCheckBox $name $args
- }
-
- proc VxRowColumn {name args} {
- eval _VxBox VtRowColumn $name $args
- }
-
- proc VxComboBox {name args} {
- eval _VxBox VtComboBox $name $args
- }
-
- proc _VxBox {cmd name args} {
- set parts [split $name .]
- set wName [lindex $parts end]
-
- # delete name
- set parts [lreplace $parts end end]
- set parent [join $parts .]
-
- # list of options that we are going to override, if any
- # of the geometry options are set, we need to set them on the
- # invisible form.
- set geoOptions {}
- foreach opt {
- leftOffset leftSide alignLeft
- rightOffset rightSide alignRight
- topOffset topSide alignTop
- bottomOffset bottomSide alignBottom
- below above
- } {
- lappend geoOptions -$opt -MOTIF_$opt -CHARM_$opt
- }
-
- # These two options are the ones that we are really interested in
-
- # These two options are the ones that we are really interested in
- # if either one of these two exist we create a form wrapper around
- # the object.
- set allOptions [concat $geoOptions "-title -label"]
-
- foreach opt $allOptions {
- set found($opt) ""
- }
-
- set lastFound ""
- set newArgs ""
- foreach arg $args {
-
- if {$lastFound != ""} {
- set found($lastFound) $arg
- set lastFound ""
- continue
- }
-
- set lastFound [lmatch -exact $allOptions $arg]
- if {$lastFound != ""} {
- continue
- }
-
- lappend newArgs $arg
- }
-
- # Create the args list for the outer form
- set boxArgs ""
- foreach opt $geoOptions {
- if {$found($opt) != ""} {
- lappend boxArgs $opt $found($opt)
- }
- }
-
- set form $parent
- if {$found(-title) != "" || $found(-label) != ""} {
- # make the form
- set boxname [format "%s_box" $wName]
-
- set form [eval VtForm $parent.$boxname $boxArgs\
- -marginHeight 0 -marginWidth 0]
-
- if {$found(-title) != ""} {
- set label [VtLabel $form.label -label $found(-title) \
- -topSide FORM]
- set target [eval $cmd $form.$wName $newArgs -topSide $label \
- -leftSide FORM -rightSide FORM -bottomSide FORM]
- } else {
- set label [VtLabel $form.label -label $found(-label) \
- -topSide FORM -bottomSide FORM]
- set target [eval $cmd $form.$wName $newArgs \
- -leftSide $label -leftOffset 5 \
- -rightSide FORM \
- -topSide FORM -bottomSide FORM]
- }
-
- VxSetVar $target "form" $form
- VxSetVar $target "label" $label
-
- } else {
- set target [eval $cmd $form.$wName $newArgs $boxArgs]
- }
-
- return $target
- }
-
-
- #@packend
-
- #@package: VisualTclX-align VxAlignBaseLines VxCenterVertically \
- VxSetLeftOffsets VxAlignedForm
-
- #================================================================== API ===
- # VxAlignBaseLines
- #
- # Given two widgets which have been created with the sourceWidget
- # -alignTop to the targetWidget, sets the top offset of the sourceWidget
- # so that its baseline lines up with the targetWidget's baseline.
- #
- # Parameters:
- # targetWidget - the widget you are aligning to
- # sourceWidget - the widget that will be adjusted
- # currentOffset - any topOffset the targetWidget already has which must
- # be taken into account (OPTIONAL, default=0)
- # Globals:
- # Returns:
- #--------------------------------------------------------------------------
- proc VxAlignBaseLines {targetWidget sourceWidget {currentOffset 0}} {
- set source [VtGetValues $sourceWidget -baseLineList]
- set target [VtGetValues $targetWidget -baseLineList]
- set diff [expr {($target - $source) + $currentOffset}]
- VtSetValues $sourceWidget -MOTIF_topOffset $diff
- }
-
- #================================================================== API ===
- # VxCenterVertically
- #
- # Given two widgets which have been created with the sourceWidget
- # -alignTop to the targetWidget, sets the top offset of the sourceWidget
- # so that the targetWidget is in the center.
- #
- # Parameters:
- # targetWidget - the widget you are centering around
- # sourceWidget - the widget that will be adjusted
- # Globals:
- # Returns:
- #--------------------------------------------------------------------------
- proc VxCenterVertically {targetWidget sourceWidget} {
- set source [VtGetValues $sourceWidget -height]
- set target [VtGetValues $targetWidget -height]
- set diff [expr {($target - $source) / 2}]
-
- VtSetValues $sourceWidget -MOTIF_topOffset $diff
- }
-
-
- #================================================================== API ===
- # VxSetLeftOffsets
- #
- # Given a list of widgets which have been created with -alignRight
- # to the previous label, sets the left offset of the first
- # widget so that all the labels fit on the form
- #
- # Parameters:
- # widgets - a list of widgets, the first widget in the list is
- # the one that gets modified
- # MOTIFOffset - any MOTIF leftOffset the first widget already has which
- # must be taken into account (OPTIONAL, default=0)
- # CHARMOffset - any CHARM leftOffset the first widget already has which
- # must be taken into account (OPTIONAL, default=0)
- # Globals:
- # Returns:
- #--------------------------------------------------------------------------
- proc VxSetLeftOffsets {widgets {MOTIFOffset 0} {CHARMOffset 0}} {
-
- set max 0
- set CHARM_max 0
- set firstWidget [lindex $widgets 0]
-
- # find the widest widget
- for {set i 0} {$i < [llength $widgets]} {incr i} {
- set width [VtGetValues [lindex $widgets $i] -width]
- if {$width > $max} then {
- set max $width
- }
- set CHARM_width [string length [VtGetValues \
- [lindex $widgets $i] -label]]
- if {$CHARM_width > $CHARM_max} then {
- set CHARM_max $CHARM_width
- }
- }
-
- # set the left offset of the first widget
- set diff [expr {$max - [VtGetValues $firstWidget -width] \
- + 1 + $MOTIFOffset}]
-
- VtSetValues $firstWidget -MOTIF_leftOffset $diff
-
- set CHARM_diff [expr {$CHARM_max - [string length [VtGetValues \
- $firstWidget -label]] \
- + 1 + $CHARMOffset}]
-
- VtSetValues $firstWidget -CHARM_leftOffset $CHARM_diff
- }
-
-
-
- # ----------------------------------------
- # VxAlignedForm
- #
- # Description:
- # Creates one or more vertically aligned widgets,
- # with right-justified labels.
- # Each Label and Widget are in their own form.
- # Their widget names may be retrieved as follows:
- #
- # (in the list below, $name is the name returned by the
- # VxAlignedForm call, and $n is the position of the widget.
- # "1" is the first widget)
- #
- # Form: VxGetVar $name "form$n"
- # Widget: VxGetVar $name "widget$n"
- # Label: VxGetVar $name "label$n"
- #
- # Usage:
- # VxAlignedForm widgetName dataList
- #
- # Arguments:
- # widgetName - Name of parent.thisWidget
- # dataList - A list of lists, each containing a label and
- # another list containing the desired widget call
- # and any desired arguments
- #
- # Example:
- # set form [VxAlignedForm $parent.Texts\
- # { {"The 1st label" {VtText -columns 30 -value "stuff 1"}}
- # {"The second label" {VtText -value "stuff 2"}}
- # {"3rd label" {VtText -value "stuff 3"}}
- # {"Combo" VtComboBox} } ]
- # --------------------
- #
- proc VxAlignedForm { args } {
- set argc [llength $args]
- if {$argc != 2} {
- error "VxAlignedForm: wrong number of args: $argc"
- }
-
- set wname [lvarpop args]
- set dataList [lvarpop args]
-
- set form [VtForm $wname -marginWidth 0 -marginHeight 0]
-
- set index 0
- set maxWidth 0
- foreach list $dataList {
- # First element is the label
- set labelstr [lindex $list 0]
- # Second element is the widget call and list-o-arguments
- set wlist [lindex $list 1]
- set widgetCall [lvarpop wlist]
-
- incr index
- set tform\
- [VtForm $form.Tform$index\
- -marginWidth 0\
- -marginHeight 0\
- -leftSide FORM\
- -rightSide FORM]
-
- set label\
- [VtLabel $tform.Label$index\
- -label $labelstr\
- -labelRight\
- -leftSide FORM\
- -rightSide NONE\
- -topSide FORM\
- -bottomSide FORM\
- -alignLeft NONE]
- set widget [eval $widgetCall $tform.Text$index $wlist]
- VtSetValues $widget\
- -alignLeft NONE\
- -leftSide $label\
- -topSide FORM\
- -bottomSide FORM\
- -rightSide FORM
- set width [VtGetValues $label -width]
- if {$width > $maxWidth} {
- set maxWidth $width
- }
- VxSetVar $form "widget$index" $widget
- VxSetVar $form "label$index" $label
- VxSetVar $form "form$index" $tform
- }
-
- set maxWidth [expr {$maxWidth + 1}]
- for {set i 1} {$i <= $index} {incr i} {
- set label [VxGetVar $form "label$i"]
- set tform [VxGetVar $form "form$i"]
- set width [VtGetValues $label -width]
- if {$width < $maxWidth} {
- set offset [expr {$maxWidth - $width}]
- VtSetValues $tform -leftOffset $offset
- }
- }
-
- return $form
- }
-
- # ----------------------------------------
-
- #@packend
-
-
-
- #@package: VisualTclX-misc VxEndFormCB VxGetShortName
-
- #================================================================== API ===
- # VxGetShortName
- #
- # Given a widget name, strips off all the parent widgets, leaving
- # the short widget name
- #
- # Parameters:
- # widget - the widget name to strip
- # Globals:
- # Returns:
- # the stripped widget name
- #--------------------------------------------------------------------------
- proc VxGetShortName {widget} {
- set wl [split $widget .]
- set wi [expr "[llength $wl] - 1"]
- set short [lindex $wl $wi]
- return $short
- }
-
- proc VxEndFormCB {cbs} {
- VtDestroyDialog [keylget cbs dialog]
- }
-
- #@packend
-
- #@package: VisualTclX-var VxSetVar VxGetVar VxWidgetVarRef
-
- #
- # _VxWidgetVarError
- #
- # Convert error in error stack to something that makes sense for the
- # variable. This is needed becaused error stacks containing upvared variables
- # don't contain the real name.
- #
- proc _VxWidgetVarError {msg realVar} {
- global errorInfo errorCode
- regsub {"var"} $msg \"$realVar\" msg
- regsub {"var"} $errorInfo \"$realVar\" errorInfo
- error $msg $errorInfo $errorCode
- }
-
- #
- # VxSetVar
- #
- # Set the value of a per-widget variable frame variable.
- #
- # Parameters:
- # o widgetName (I) - Name of widget that the variable is associated with.
- # o varName (I) - Name of the variable. May be a scalar or array reference.
- # o value (I) - The value is assigned to the variable
- # Returns:
- # Value is returned.
- #
- proc VxSetVar {widgetName varName value} {
- upvar #0 "VTVars:$widgetName:$varName" var
-
- set stat [catch {
- set result [set var $value]
- } msg]
-
- if {$stat == 1} {
- _VxWidgetVarError $msg $varName
- }
- return $result
- }
-
- #
- # VxGetVar
- #
- # Get the value of a per-widget variable frame variable.
- #
- # Parameters:
- # o widgetName (I) - Name of widget that the variable is associated with.
- # o varName (I) - Name of the variable. May be a scalar or array reference.
- # Returns:
- # Value is returned.
- #
- proc VxGetVar {widgetName varName} {
- upvar #0 "VTVars:$widgetName:$varName" var
-
- set stat [catch {
- set result [set var]
- } msg]
-
- if {$stat == 1} {
- _VxWidgetVarError $msg $varName
- }
- return $result
- }
-
- #
- # VxWidgetVarRef
- #
- # Return a "reference" for per-widget variable frames variable. This allows
- # the variable to be passed by reference to other Tcl commands. eg:
- #
- # array names [VxWidgetVarRef my.widget.path data]
- #
- # Parameters:
- # o widgetName (I) - Name of widget that the variable is associated with.
- # o varName (I) - Name of the variable. May be a scalar or array, but not
- # an element of the arrray.
- # Returns:
- # A reference to the variable usable in the current scope.
- #
- proc VxWidgetVarRef {widgetName varName} {
- set ref "VTVars:$widgetName:$varName"
- uplevel global $ref
- return $ref
- }
-
-
- #@package: VisualTclX-SpinButton VxSpinButton VxSpinButtonSetMinValue \
- VxSpinButtonSetMaxValue
-
- #================================================================== INT ===
- # SB:CheckBoundsCB
- # Checks the text field value is within the upper and lower bounds.
- # Parameters:
- # instance - the widget name of the enclosing form of the SpinButton
- # underCB - a callback for when the value goes below the lower
- # bound. If set to null, wraps the value around.
- # overCB - a callback for when the value goes over the upper
- # bound. If set to null, wraps the value around.
- # Globals:
- # SBlower - array of lower value boundary values, indexed by
- # instance
- # SBupper - array of upper value boundary values, indexed by
- # instance
- # Returns:
- #--------------------------------------------------------------------------
- proc SB:CheckBoundsCB {instance underCB overCB cbs} {
-
- global SBlower SBupper
-
- set field [VxGetVar $instance text]
- set newValue [VtGetValues $field -value]
-
- if {![ctype digit $newValue]} then {
- VtSetValues $field -value $SBlower($instance)
- return
- }
-
- if {$newValue > $SBupper($instance)} then {
- if {[string length $overCB]==0} then {
- VtSetValues $field -value $SBupper($instance)
- return
- } else {
- $overCB $cbs
- return
- }
- }
-
- if {$newValue < $SBlower($instance)} then {
- if {[string length $underCB]==0} then {
- VtSetValues $field -value $SBlower($instance)
- return
- } else {
- $underCB $cbs
- return
- }
- }
-
- } ;# SB:CheckBoundsCB
-
-
- #================================================================== INT ===
- # SB:ChangeValueCB
- # Increases or decreases the SpinButton value, wrapping the value
- # around upper and lower bounds.
- # Parameters:
- # instance - the widget name of the enclosing form of the SpinButton
- # underCB - a callback for when the value goes below the lower
- # bound. If set to null, wraps the value around.
- # overCB - a callback for when the value goes over the upper
- # bound. If set to null, wraps the value around.
- # increment - how much to increase/decrease the value by
- # direction - up: increase the value, down: decrease the value
- # upOp - operation to perform on increment when the "up" button
- # is pressed
- # dnOp - operation to perform on increment when the "down" button
- # is pressed
- # Globals:
- # SBlower - array of lower value boundary values, indexed by
- # instance
- # SBupper - array of upper value boundary values, indexed by
- # instance
- # Returns:
- #--------------------------------------------------------------------------
- proc SB:ChangeValueCB {instance underCB overCB increment \
- direction upOp dnOp cbs} {
-
- global SBlower SBupper
-
- set field [VxGetVar $instance text]
-
- set currentValue [VtGetValues $field -value]
- if {[string length $currentValue] == 0} then {
- set currentValue $SBlower($instance)
- }
- if {[ctype digit $currentValue] == 0} then {
- set currentValue $SBlower($instance)
- }
-
- if {$direction == "up"} {
- set newValue [expr "$currentValue $upOp $increment"]
- } else {
- set newValue [expr "$currentValue $dnOp $increment"]
- }
-
- if {$newValue>$SBupper($instance)} then {
- if {[string length $overCB]==0} then {
- if {$direction == "up"} {
- set newValue $SBlower($instance)
- } else {
- set newValue $SBupper($instance)
- }
- } else {
- $overCB $cbs
- return
- }
- }
-
- if {$newValue<$SBlower($instance)} then {
- if {[string length $underCB]==0} then {
- if {$direction == "up"} {
- set newValue $SBlower($instance)
- } else {
- set newValue $SBupper($instance)
- }
- } else {
- $underCB $cbs
- return
- }
- }
-
- VtSetValues $field -value $newValue
-
- } ;# SB:ChangeValueCB
-
-
- #================================================================== EXT ===
- # VxSpinButtonSetMinValue
- # Sets the lower boundary for a spin button
- # Parameters:
- # instance - the instance name of the SpinButton
- # lower - the lower value boundary
- # Globals:
- # SBlower - array of lower value boundary values, indexed by
- # instance
- # Returns:
- #--------------------------------------------------------------------------
- proc VxSpinButtonSetMinValue {instance lower} {
- global SBlower
-
- set SBlower($instance) $lower
-
- set textW [VxGetVar $instance text]
-
- set currentValue [VtGetValues $textW -value]
- if {[string length $currentValue] == 0} then {
- set currentValue $SBlower($instance)
- }
- if {[ctype digit $currentValue] == 0} then {
- set currentValue $SBlower($instance)
- }
-
- if {$currentValue < $SBlower($instance)} then {
- set currentValue $SBlower($instance)
- }
-
- VtSetValues $textW -value $currentValue
-
- } ;# VxSpinButtonSetMinValue
-
-
- #================================================================== EXT ===
- # VxSpinButtonSetMaxValue
- # Sets the upper boundary for a spin button
- # Parameters:
- # instance - the instance name of the SpinButton
- # upper - the upper value boundary
- # Globals:
- # SBupper - array of upper value boundary values, indexed by
- # instance
- # Returns:
- #--------------------------------------------------------------------------
- proc VxSpinButtonSetMaxValue {instance upper} {
- global SBupper
-
- set SBupper($instance) $upper
-
- set textW [VxGetVar $instance text]
-
- set currentValue [VtGetValues $textW -value]
- if {[string length $currentValue] == 0} then {
- set currentValue $SBlower($instance)
- }
- if {[ctype digit $currentValue] == 0} then {
- set currentValue $SBlower($instance)
- }
-
- if {$currentValue > $SBupper($instance)} then {
- set currentValue $SBupper($instance)
- }
-
- VtSetValues $textW -value $currentValue
-
- } ;# VxSpinButtonSetMaxValue
-
-
- #================================================================== EXT ===
- # getPixmapDirectory
- # Returns the location of the Visual Tcl pixmap directory.
- # Parameters:
- # NONE
- #
- proc getPixmapDirectory {} {
- global env
- if {[info exists env(VTCL_HOME)]} {
- set pixmapDir "$env(VTCL_HOME)/pixmaps"
- } else {
- if {[info exists env(WSHOMEDIR)]} {
- set pixmapDir "$env(WSHOMEDIR)/pixmaps"
- } else {
- set pixmapDir "/lib/vtcl/pixmaps"
- }
- }
- return $pixmapDir
- }
-
-
- #================================================================== EXT ===
- # VxSpinButton
- # Creates a SpinButton, which consists of a text field and two
- # buttons which increase and decrease the numeric value in the text
- # field within upper and lower bounds.
- # Parameters:
- # widget - the widget name of this SpinButton
- # width - the width of the Text widget
- # lower - the lower boundary value
- # underCB - a callback for when the value goes below the lower
- # bound. If set to "", the package automatically wraps the
- # value around to the upper value.
- # upper - the upper boundary value
- # overCB - a callback for when the value goes over the upper
- # bound. If set to "", the package automatically wraps the
- # value around to the lower value.
- # increment - how much to increase/decrease the value by
- # default - the inital default value
- # userCB - a callback which checks the value of the Text widget, or ""
- # for no callback
- # position - standard geometryArgs for the Text widget.
- # upOp (OPT)- operation to perform on increment when the "up" button
- # is pressed (+ if not present)
- # dnOp (OPT)- operation to perform on increment when the "down" button
- # is pressed (- if not present)
- # Globals:
- # SBlower - array of lower boundary values, indexed by widget
- # SBupper - array of upper boundary values, indexed by widget
- # Returns:
- # The name of the enclosing form widget
- # Notes:
- # Attached to the form widget returned, is the name of the text widget
- # and rowcol widget containing the buttons:
- #
- # VxGetVar $sb text for the text widget
- # VxGetVar $sb rowcol for the rowcol widget
- #--------------------------------------------------------------------------
- proc VxSpinButton {widget width lower underCB upper overCB \
- increment default userCB position \
- {upOp "+"} {dnOp "-"}} {
-
- global SBlower SBupper
-
-
- #set iconPath /usr/lib/X11/sco/ScoAdmin/common
- set iconPath [getPixmapDirectory]
-
- set SB [eval VtForm $widget -marginHeight 0 -marginWidth 0 $position]
-
- if {$userCB != ""} then {
- set text [VtText $SB.text -rows 1 -columns $width \
- -value $default -callback $userCB \
- -leftSide FORM -topSide FORM -bottomSide FORM \
- -MOTIF_topOffset 2 -MOTIF_bottomOffset 4 ]
- } else {
- set text [VtText $SB.text -rows 1 -columns $width \
- -value $default \
- -callback "SB:CheckBoundsCB $SB \"$underCB\" \"$overCB\""\
- -leftSide FORM -topSide FORM -bottomSide FORM \
- -MOTIF_topOffset 2 -MOTIF_bottomOffset 4 ]
- }
-
- set SBlower($SB) $lower
- set SBupper($SB) $upper
-
- if {! [VtInfo -charm]} then {
- set rowcol [VtRowColumn $SB.rc -packing TIGHT -spacing 0 \
- -leftOffset 0 -leftSide NONE -topSide FORM -rightSide FORM \
- -bottomSide FORM -xmArgs {XmNmarginHeight 0 XmNmarginWidth 0}]
-
- VtSetValues $text -rightSide $rowcol \
- -rightOffset 0
-
- set upBut [VtPushButton $rowcol.up \
- -pixmap $iconPath/up_ptr.xbm \
- -callback "SB:ChangeValueCB $SB {$underCB} \
- {$overCB} $increment up $upOp $dnOp" \
- -label "^"]
-
- set downBut [VtPushButton $rowcol.down \
- -pixmap $iconPath/down_ptr.xbm \
- -callback "SB:ChangeValueCB $SB {$underCB} \
- {$overCB} $increment down $dnOp $dnOp" \
- -label "v"]
-
- VxSetVar $SB rowcol $rowcol
- VxSetVar $SB upBut $upBut
- VxSetVar $SB downBut $downBut
- } else {
- VtSetValues $text -rightSide FORM
- }
-
- VxSetVar $SB text $text
-
- return $SB
-
- } ;# VxSpinButton
-
- #@packend
-
-
-
- #@package: VisualTclX-backwardsCompat WxMenu WxMenuGetButton WxOptionMenu \
- WxOptionMenuGetSelected WxOptionMenuReplaceOptions WxOptionMenuSetSelected \
- WxList WxText WxRowColumn WxRadioBox WxCheckBox WxComboBox \
- WxAlignBaseLines WxCenterVertically WxSetLeftOffsets WxAlignedForm \
- WxEndFormCB WxGetShortName WxSetVar WxGetVar WxWidgetVarRef WxSpinButton \
- WxSpinButtonSetMinValue WxSpinButtonSetMaxValue
-
- proc WxMenu {dlog menubar menuList defaultCB} {
- return [VxMenu $dlog $menubar $menuList $defaultCB]
- }
-
- proc WxMenuGetButton {dlog name} {
- return [VxMenuGetButton $dlog $name]
- }
-
- proc WxOptionMenu {name label options CB selection} {
- return [VxOptionMenu $name $label $options $CB $selection]
- }
-
- proc WxOptionMenuGetSelected {menu} {
- return [VxOptionMenuGetSelected $menu]
- }
-
- proc WxOptionMenuSetSelected {menu selected} {
- return [VxOptionMenuSetSelected $menu $selected]
- }
-
- proc WxOptionMenuReplaceOptions {menu options selection} {
- return [VxOptionMenuReplaceOptions $menu $options $selection]
- }
-
- proc WxList {name args} {
- return [eval "VxList \"$name\" $args"]
- }
-
- proc WxText {name args} {
- return [eval "VxText \"$name\" $args"]
- }
-
- proc WxRadioBox {name args} {
- return [eval "VxRadioBox \"$name\" $args"]
- }
-
- proc WxCheckBox {name args} {
- return [eval "VxCheckBox \"$name\" $args"]
- }
-
- proc WxRowColumn {name args} {
- return [eval "VxRowColumn \"$name\" $args"]
- }
-
- proc WxComboBox {name args} {
- return [eval "VxComboBox \"$name\" $args"]
- }
-
- proc WxAlignBaseLines {targetWidget sourceWidget {currentOffset 0}} {
- return [VxAlignBaseLines $targetWidget $sourceWidget $currentOffset]
- }
-
- proc WxCenterVertically {targetWidget sourceWidget} {
- return [VxCenterVertically $targetWidget $sourceWidget]
- }
-
- proc WxSetLeftOffsets {widgets {MOTIFOffset 0} {CHARMOffset 0}} {
- return [VxSetLeftOffsets $widgets $MOTIFOffset $CHARMOffset]
- }
-
- proc WxAlignedForm {args} {
- return [eval "VxAlignedForm $args"]
- }
-
- proc WxGetShortName {widget} {
- return [VxGetShortName $widget]
- }
-
- proc WxEndFormCB {cbs} {
- return [VxEndFormCB $cbs]
- }
-
- proc WxSetVar {widgetName varName value} {
- return [VxSetVar $widgetName $varName $value]
- }
-
- proc WxGetVar {widgetName varName} {
- return [VxGetVar $widgetName $varName]
- }
-
- proc WxWidgetVarRef {widgetName varName} {
- return [VxWidgetVarRef $widgetName $varName]
- }
-
- proc WxSpinButtonSetMinValue {instance lower} {
- return [VxSpinButtonSetMinValue $instance $lower]
- }
-
- proc WxSpinButtonSetMaxValue {instance upper} {
- return [VxSpinButtonSetMaxValue $instance $upper]
- }
-
- proc WxSpinButton {widget width lower underCB upper overCB \
- increment default userCB position \
- {upOp "+"} {dnOp "-"}} {
- return [VxSpinButton $widget $width $lower $underCB $upper $overCB \
- $increment $default $userCB $position $upOp $dnOp]
- }
-